//
//  BaseUITabBarController.m
//  GTTool
//
//  Created by GTO on 2018/8/24.
//  Copyright © 2018年 GTO. All rights reserved.
//

#import "BaseUITabBarController.h"
#import "BaseUINavigationController.h"
#import "HomeViewController.h"
#import "MineViewController.h"
@interface BaseUITabBarController ()

@end

@implementation BaseUITabBarController

+(void)initialize{
    //获取当前页面下所有的item
    UITabBarItem *item = [UITabBarItem appearance];
    //设置当前页面下所有item的颜色
    
    [item setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor blackColor]} forState:UIControlStateSelected];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.automaticallyAdjustsScrollViewInsets = NO;
    [[UITabBar appearance] setShadowImage:[UIImage new]];
    [[UITabBar appearance] setBackgroundImage:[[UIImage alloc]init]];
    [self dropShadowWithOffset:CGSizeMake(0, -0.3)    radius:.3
                         color:[UIColor grayColor]
                       opacity:0.3];
    self.tabBar.backgroundColor = [UIColor colorWithRed:250/255.0 green:250/255.0 blue:250/255.0 alpha:1];
    [self addChildVCS];
}
#pragma mark - 添加子控制器
-(void)addChildVCS{
    
    // 首页
    
    HomeViewController *mainVC = [[HomeViewController alloc] init];
    
    [self addChildVC:mainVC andTitle:@"首页" andImage:@"" andSelectedImage:@""];
    
    //我的
    MineViewController *mineVc = [[MineViewController alloc] init];
    
    [self addChildVC:mineVc andTitle:@"我的" andImage:@"" andSelectedImage:@""];
    
    
}

- (void)addChildVC:(UIViewController *)childC andTitle:(NSString *)title andImage:(NSString *)image andSelectedImage:(NSString *)selectedImage{
    childC.title = title;
    childC.tabBarItem.image = [[UIImage imageNamed:image]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    childC.tabBarItem.selectedImage = [[UIImage imageNamed:selectedImage]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    [childC.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName: ColorRGB(72, 75, 94)} forState:UIControlStateSelected];
    [childC.tabBarItem setTitlePositionAdjustment:UIOffsetMake(0, -2)];
    BaseUINavigationController *navigationVC = [[BaseUINavigationController alloc] initWithRootViewController:childC];
    [self addChildViewController:navigationVC];
}

- (void)dropShadowWithOffset:(CGSize)offset
                      radius:(CGFloat)radius
                       color:(UIColor *)color
                     opacity:(CGFloat)opacity {
    
    // Creating shadow path for better performance
    CGMutablePathRef path = CGPathCreateMutable();
    CGPathAddRect(path, NULL, self.tabBar.bounds);
    self.tabBar.layer.shadowPath = path;
    CGPathCloseSubpath(path);
    CGPathRelease(path);
    
    self.tabBar.layer.shadowColor = color.CGColor;
    self.tabBar.layer.shadowOffset = offset;
    self.tabBar.layer.shadowRadius = radius;
    self.tabBar.layer.shadowOpacity = opacity;
    
    // Default clipsToBounds is YES, will clip off the shadow, so we disable it.
    self.tabBar.clipsToBounds = NO;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
